import BNodeDecorator from "../base/BNodeDecorator";
import {ActionResult} from "../BTreeActionResult";
const {ccclass, property} = cc._decorator;
//<Tree-Category>{"path":"decorators","color":"#fff419","tip":""}</Tree-Category>
@ccclass
/**
 * 结果翻转
 */
export default class BNodeRepeater extends BNodeDecorator {

    private maxLoop: number = 0;
    private curLoop: number = 0;

    public onEnter(): void {
        this.maxLoop = this.parameter["maxLoop"];
    }

    public onExcute(): ActionResult {
        if (!this.child) {
            return ActionResult.ERROR;
        }
        let status: ActionResult = ActionResult.SUCCESS;

        while (this.curLoop < this.maxLoop) {
            status = this.child.runNode();
            if (status == ActionResult.SUCCESS || status == ActionResult.FAILURE)
                this.curLoop++;
            else
                break;
        }
        return status;
    }
}
